import { getMsbd, addedlists, deletelist, modificationsapi } from '../../api/msbd'
export default {
  namespaced: true,
  state: {
    list: [],
    classify: [],
    currentpage: 0,
    pageSize: 20,
    total: 0
  },
  mutations: {
    //获取值渲染表格
    GETDATA_MSBD(state, res) {
      state.list = res;
    },
    SET_CLASSIFY(state, classify) {
      state.classify = classify
    },
    SET_TOTAL(state, res) {
      state.total = res
    },
    //当前页
    SET_CURRENTPAGE(state, val) {
      state.currentPage = val
    },
    //每页多少条
    SET_PAGESIZE(state, val) {
      state.pageSize = val
    }
  },
  actions: {
    //获取值渲染表格
    async getmsbddata({ state, commit }, ipt) {
      let transferparameters = { orderby: 'id', sort: 'desc', currentPage: state.currentPage, pageSize: state.pageSize }
      if (ipt) {
        transferparameters.searchVal = ipt
      }
      let r = await getMsbd(transferparameters)
      commit('GETDATA_MSBD', r.data)
      commit('SET_CLASSIFY', r.classify)
      // console.log(data)
      commit('SET_TOTAL', r.total[0].total)
      // console.log(r)
    },
    //新增
    async addedlist({ commit, dispatch }, form) {
      await addedlists(form)
      await dispatch('getmsbddata')
    },
    //删除
    async deletelist({ commit, dispatch }, id) {
      await deletelist({ id: id })
    },
    //修改
    async modifications({ commit }, form) {
      await modificationsapi(form)
    }
  }
}